package com.coffeeloversupportlibrary.coffeelover.domain.article.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.coffeeloversupportlibrary.R;
import com.coffeeloversupportlibrary.coffeelover.domain.article.entity.Article;
import com.coffeeloversupportlibrary.coffeelover.domain.article.manger.ScaleTransformer;
import com.coffeeloversupportlibrary.coffeelover.domain.article.type.QuintessenceType;
import com.coffeeloversupportlibrary.databinding.QuintessenceShowBinding;

import java.util.List;

import github.hellocsl.layoutmanager.gallery.GalleryLayoutManager;

/**
 * @author puyv
 * @createTime 2021/11/6 20:18
 * @projectName CoffeeLoverSupportLibrary
 * @className QuintessenceAdapter.java
 * @description TODO
 */
public class QuintessenceAdapter implements Adapter<List<QuintessenceType>> {
    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.quintessence_show,parent,false);
        QuintessenceShowBinding quintessenceShowBinding=QuintessenceShowBinding.bind(view);
        return new QuintessenceArticleViewHolder(quintessenceShowBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull List<QuintessenceType> items, @NonNull RecyclerView.ViewHolder holder, int position) {
        QuintessenceType item=items.get(position);
        List<Article> list=item.getItems();

        GalleryLayoutManager layoutManager = new GalleryLayoutManager(GalleryLayoutManager.HORIZONTAL);
        layoutManager.setItemTransformer(new ScaleTransformer());
        layoutManager.attach(((QuintessenceArticleViewHolder)holder).quintessenceShowBinding.quintessenceItemView, 3);
        layoutManager.scrollToPosition(3);

        QuintessenceListAdapter adapter= new QuintessenceListAdapter(list);



        //精华列表
        ((QuintessenceArticleViewHolder)holder).quintessenceShowBinding.quintessenceItemView.setAdapter(adapter);
        ((QuintessenceArticleViewHolder)holder).quintessenceShowBinding.quintessenceItemView.setLayoutManager(layoutManager);


    }

    static class QuintessenceArticleViewHolder extends RecyclerView.ViewHolder{
        private QuintessenceShowBinding quintessenceShowBinding;
        public QuintessenceArticleViewHolder(@NonNull QuintessenceShowBinding quintessenceShowBinding) {
            super(quintessenceShowBinding.getRoot());
            this.quintessenceShowBinding=quintessenceShowBinding;
        }
    }
}

